package com.order.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.order.dao.bean.Category;

public class CateServlet extends HttpServlet
{
	public void doGet(HttpServletRequest req,HttpServletResponse resp)
            throws ServletException,IOException
            {
            	doPost(req,resp);
            }

   public void doPost(HttpServletRequest req,HttpServletResponse resp)
             throws ServletException,IOException   
             {
             		resp.setContentType("text/html;charset=gbk");
             		req.setCharacterEncoding("gbk");
                	String action=req.getParameter("test");
                	System.out.print(action);
                	Category category=new Category();
                	if(action.equals("addcg"))
                	{
                		String cgname=req.getParameter("cgname");
                		String cgbz=req.getParameter("cgbz");
                		System.out.println(cgname+cgbz);
                		category.addcate(cgname, cgbz);
                		this.forward("category.jsp", req, resp);
                	}
                	else if(action.equals("delcg"))
                	{
                		String cgname=req.getParameter("cgname");
                		category.delcate(cgname);
                		this.forward("category.jsp", req, resp);
                	}
             } 
   public void forward(String path,HttpServletRequest req,
  HttpServletResponse resp)
throws ServletException,
  IOException
  {
  	req.getRequestDispatcher("/"+path).include(req,resp);
  }            
}
